package com.zhao.modleclass.activity;

import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

import com.zhao.modleclass.R;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.PlatformDb;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;

/**
 * Created by 张博文 on 2016/12/12.
 */

public class LoginActivity extends AppCompatActivity implements View.OnClickListener,KeyEvent.Callback{
    private EditText et_login_sms,et_login_phone;
    private Button et_login_fasms,login;
    private static String APPKEY="19f5f30bffe46";
    // 填写从短信SDK应用后台注册得到的APPSECRET 
    private static String APPSECRET = "ca2b832539bb5a1b479ff3c6f281c497";

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        //设置状态栏的颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            //获取样式中的属性值
            TypedValue typedValue = new TypedValue();
            this.getTheme().resolveAttribute(Color.parseColor("#FF4081"), typedValue, true);
            int[] attribute = new int[]{Color.parseColor("#FF4081")};
            TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);
            int color = array.getColor(0, Color.parseColor("#FF4081"));
            array.recycle();
            window.setStatusBarColor(color);
        }
        et_login_fasms= (Button) findViewById(R.id.et_login_fasms);
        login= (Button) findViewById(R.id.login);
        et_login_phone= (EditText) findViewById(R.id.et_login_phone);
        et_login_sms= (EditText) findViewById(R.id.et_login_sms);

    }


    public void onClick(View view){
        switch (view.getId()){
            case R.id.iv_login_close:
                finish();
                break;
            case R.id.et_login_fasms:
                break;
            case R.id.login:
                break;
            case R.id.iv_login_pc:

                break;
            case R.id.iv_login_wx:

                break;
            case R.id.iv_login_qq:

                break;
            case R.id.iv_login_sina:
                Login();
                break;
        }
    }
    /**
     * 第三方登陆
     */
    public void Login(){
        Platform platform= ShareSDK.getPlatform(SinaWeibo.NAME);
        platform.SSOSetting(true);
        platform.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                //判断是否获取到用户信息
                if(action==Platform.ACTION_USER_INFOR){
                    //获取相应的平台数据  新浪微博的用户数据
                    PlatformDb platformDb=platform.getDb();
                    platformDb.getUserIcon();//获取用户头像
                    String userId=platformDb.getUserId();//获取当前第三方登陆的用户id
                    String name=platformDb.getUserName();//获取当前第三方登陆的用户名称
                    Log.i("tag","userId="+userId+",userName="+name);
                }
            }
            /** 授权失败 */
            @Override
            public void onError(Platform platform, int i, Throwable t) {


            }
            /** 取消授权 */
            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        platform.authorize();
        platform.SSOSetting(true);
        platform.showUser(null);//执行登陆 要数据不要功能 登陆后回调获取数据
//        platform.showUser("id");
    }
}
